package T2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main1 {

	public static void main(String[] args) {
		Map<String,Integer> dict=new HashMap<String,Integer>();
		Scanner sc=new Scanner(System.in);
		while(sc.next()!="!!!!!"){
			String key=sc.next();
			Integer value=dict.get(key);
			if(value==null){
				dict.put(key, 1);
			}
			else dict.put(key, ++value);
		}
		System.out.println(dict.size());
		List<Entry<String,Integer>> list=new ArrayList<>();
		for(Entry<String,Integer> e:dict.entrySet()){
			list.add(e);
		}
		Collections.sort(list,new Comparator<Entry<String,Integer>>(){

			@Override
			public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
				if(o1.getValue()!=o2.getValue()){
				return o2.getValue()-o1.getValue();
				}
				else{
					return o1.getKey().compareTo(o2.getKey());
				}
			}
		});
		System.out.println(list.toString());

	}

}
